package org.activequant.core.domainmodel.data;

import java.io.Serializable;
import java.util.List;

import org.activequant.core.domainmodel.SeriesSpecification;
import org.activequant.core.domainmodel.marketdepth.MarketDepth;
import org.activequant.core.types.TimeStamp;
import org.activequant.util.exceptions.ValueNotFoundException;
import org.activequant.util.tools.ArrayUtils;

/**
 * A TimeSeries(ArrayList subclass) whose elements are MarketDepth objects.<br/>
 * Holds the following inherited/associated variables:
 * <ul>
 * <li>id(Long)</li>
 * <li>seriesSpecification(SeriesSpecification)</li>
 * <li>inherited list of elements (List&lt;MarketDepth&gt;)</li>
 * </ul>
 *  @author dmisev
 */
	public class MarketDepthSeries extends TimeSeries<MarketDepth> implements Serializable {

		private static final long serialVersionUID = -3722093387498618030L;
		
	    /**
	     * an empty MarketDepthSeries constructor.
	     */
	    public MarketDepthSeries() {
	    	
	    }

	    /**
	     * constructs  a MarketDepthSeries(ArrayList and TimeSeries subclass) using the given marketDepths(List&lt;MarketDepth&gt;) to set its MarketDepth elements.
	     * @param marketDepths
	     */
	    public MarketDepthSeries(List<MarketDepth> marketDepths) {
	    	super(marketDepths);
	    }
	    /**
	     * Constructs a MarketDepthSeries(ArrayList and TimeSeries subclass) using the given spec(SeriesSpecification) and marketDepths(List&lt;MarketDepth&gt;) to set its associated 
		 * seriesSpecification(SeriesSpecification) and its MarketDepth elements.
	     * @param spec
	     * @param marketDepths
	     */
	    public MarketDepthSeries(SeriesSpecification spec, List<MarketDepth> marketDepths) {
	    	super(marketDepths);
	    	setSeriesSpecification(spec);
	    }
	    
	    
	    /**
	     * constructs a MarketDepthSeries(ArrayList and TimeSeries subclass) using the given marketDepths(MarketDepth...) to set its MarketDepth elements.
	     * @param marketDepths
	     */
	    public MarketDepthSeries(MarketDepth... marketDepths) {
	    	this(ArrayUtils.asList(marketDepths));
	    }
	    /**
	     * Constructs a MarketDepthSeries(ArrayList and TimeSeries subclass) using the given spec(SeriesSpecification) and marketDepths(MarketDepth...) to set its associated 
		 * seriesSpecification(SeriesSpecification) and its MarketDepth elements.
	     * @param spec
	     * @param marketDepths
	     */
	    public MarketDepthSeries(SeriesSpecification spec, MarketDepth... marketDepths) {
	    	this(marketDepths);
	    	setSeriesSpecification(spec);
	    }
	    /**
	     * Sets the elements of this MarketDepthSeries(ArrayList and TimeSeries subclass) with the given marketDepths(MarketDepth...).
	     * @param marketDepths
	     */
	    public void setMarketDepths(MarketDepth... marketDepths) {
	    	setMarketDepths(ArrayUtils.asList(marketDepths));
	    }
	    /**
	     * Sets the elements of this MarketDepthSeries(ArrayList and TimeSeries subclass) with the given marketDepths(List&lt;MarketDepth&gt;).
	     * @param marketDepths
	     */
	    public void setMarketDepths(List<MarketDepth> marketDepths) {
	    	clear();
	    	addAll(marketDepths);
	    }
	    /**
	     * returns a MarketDepth[] array containing the elements of this MarketDepthSeries(ArrayList and TimeSeries subclass)
	     * @return
	     */
	    public MarketDepth[] getMarketDepth() {
	    	return ArrayUtils.asArray(this, MarketDepth.class);
	    }
		
	    /**
	     * clone this MarketDepthSeries instance.
	     * @return cloned object
	     */
		public MarketDepthSeries clone() {
			MarketDepth[] clonedMarketDepths = new MarketDepth[size()];
			MarketDepth[] marketDepths = toArray(new MarketDepth[]{});
			for(int i = 0; i < marketDepths.length; i++) {
				clonedMarketDepths[i] = marketDepths[i].clone();
			}
			MarketDepthSeries clone = new MarketDepthSeries(seriesSpecification, clonedMarketDepths);
			return clone;
		}
		/**
		 * returns a MarketDepthSeries containing the MarketDepth elements whose TimeStamps are within(inclusive) the given start-end(TimeStamp) interval
		 */
	    public MarketDepthSeries getTimeFrame(TimeStamp start, TimeStamp end) {
	    	return (MarketDepthSeries) super.getTimeFrame(start, end);
	    }
		/**
		 * returns a MarketDepthSeries containing the MarketDepth elements within(inclusive) the given start-end(int) index interval
		 */
		public MarketDepthSeries subList(int start, int end) throws ValueNotFoundException {
			return (MarketDepthSeries) super.subList(start, end);
		}
		/**
		 * returns a MarketDepthSeries containing the MarketDepth elements whose TimeStamps are within(inclusive) the given start-end(TimeStamp) interval
		 */
		public MarketDepthSeries subList(TimeStamp start, TimeStamp end) throws ValueNotFoundException {
			return (MarketDepthSeries) super.subList(start, end);
		}		
		
	}